//------------------------------------------------------Table1_descriptives.do
// Table 1 Descriptives
// --------------------------------------------------------------------------
version 15 // ensure compatibility
clear all // start in a clean state
cls // clear the results window
set more off // show all output, dont wait if screen full
set seed 12345 // see note below
set rmsg on // displays how time to execute command s
cd "C:\Users\wachb\OneDrive - UvA\WInequality\Replicate_Analysis"
capture log close // closes any log file if currently open
log using Table1_descriptives, replace text

//open the data
use "C:\Users\wachb\OneDrive - UvA\WInequality\Replicate_Analysis\countryxyzcorr.dta"

label var z_meanUDS "Unified Democracy Score"
label var z_logRGTQ "Social Trust"
label var z_MeanGiniSWIID "Gini Income"
label var z_logMeanGDP "Gross Domestic Product"
label var z_GiniWealth "Gini Wealth"
label var z_prepr "Trust in Representative Institutions"
label var z_pimpl "Trust in Implementing Institutions"
label var t "Time Interval"
label var meanUDS "Unified Democracy Score"
label var RGTQ "Social Trust"
label var MeanGiniSWIID "Gini Income"
label var MeanGDP "Gross Domestic Product"
label var GiniWealth "Gini Wealth"
label var prepr "Trust in Representative Institutions"
label var pimpl "Trust in Implementing Institutions"

//Table 1
cd "C:\Users\wachb\OneDrive - UvA\WInequality\Replicate_Analysis"
eststo clear
eststo first: estpost sum RGTQ GiniWealth MeanGiniSWIID MeanGDP meanUDS if t == 1 & GTQmis ==5
eststo second: estpost sum RGTQ GiniWealth MeanGiniSWIID MeanGDP meanUDS if t == 2 & GTQmis ==5
eststo third: estpost sum RGTQ GiniWealth MeanGiniSWIID MeanGDP meanUDS if t == 3 & GTQmis ==5
esttab first second third using Table1_GTQ.rtf, replace main(mean %10.3f) aux(sd) varwidth(25) ///
label title(Summary Statistics (Social Trust)) nonotes nogaps nonumbers  ///
addn(Note.---All entries are means over countries; Standard deviations in parentheses; ///
For Social Trust the entry is the mean percentage expressing trust in most people. ///
Gross Domestic Product = GDP per capita at purchasing power parity 2017 international dollar.) ///
mtitles("Time Interval 1" "Time Interval 2" "Time Interval 3") substitute("\fs20" "\fs24" "Observations" "\i N")

//esttab fourth ... sixth and esttab seventh ... ninth create two summary tables for institutional trust.  
eststo clear
eststo fourth: estpost sum prepr GiniWealth MeanGiniSWIID MeanGDP meanUDS if t == 1 & preprmis ==5
eststo fifth: estpost sum prepr GiniWealth MeanGiniSWIID MeanGDP meanUDS if t == 2 & preprmis ==5
eststo sixth: estpost sum prepr GiniWealth MeanGiniSWIID MeanGDP meanUDS if t == 3 & preprmis ==5
esttab fourth fifth sixth using Table1_prepr.rtf, replace main(mean %10.3f) aux(sd) varwidth(25) ///
label title(Summary Statistics (Trust in Representative Institutions)) nonotes nogaps nonumbers  ///
addn(Note.---All entries are means over countries; Standard deviations in parentheses; For Social Trust the ///
entry is the mean percentage expressing trust in most people. Gross Domestic Product = GDP per capita at ///
purchasing power parity 2017 international dollar.) ///
mtitles("Time Interval 1" "Time Interval 2" "Time Interval 3") substitute("\fs20" "\fs24" "Observations" "\i N")

eststo clear
eststo seventh: estpost sum pimpl GiniWealth MeanGiniSWIID MeanGDP meanUDS if t == 1 & pimplmis ==5
eststo eighth: estpost sum pimpl GiniWealth MeanGiniSWIID MeanGDP meanUDS if t == 2 & pimplmis ==5
eststo ninth: estpost sum pimpl GiniWealth MeanGiniSWIID MeanGDP meanUDS if t == 3 & pimplmis ==5
esttab seventh eighth ninth using Table1_pimpl.rtf, replace main(mean %10.3f) aux(sd) varwidth(25) ///
label title(Summary Statistics (Trust in Implementing Institutions)) nonotes nogaps nonumbers  ///
addn(Note.---All entries are means over countries; Standard deviations in parentheses; For Social Trust ///
the entry is the mean percentage expressing trust in most people. Gross Domestic Product = GDP per capita ///
at purchasing power parity 2017 international dollar.) ///
mtitles("Time Interval 1" "Time Interval 2" "Time Interval 3") substitute("\fs20" "\fs24" "Observations" "\i N")

//The political trust tables above are identical, therefore I merged them into one, but kept the row with the label of the dep. vars.
//In one case (Saudi Arabia) only trust in government has been asked, resulting in a smaller valid N ///
//don't save data; no new vars are made.
//manually formatted in the main document; title changed, removed depvar; added a line under the depvars. other aesthetic changes are in "Changes made to tables.docx"

